package com.ruoyi.database.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.database.domain.TbProductPackage;
import com.ruoyi.database.service.ITbProductPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 套餐管理Controller
 *
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/package")
public class TbProductPackageController extends BaseController
{
    @Autowired
    private ITbProductPackageService tbProductPackageService;

    /**
     * 查询套餐管理列表
     */
    @RequiresPermissions("system:package:list")
    @GetMapping("/list")
    public TableDataInfo list(TbProductPackage tbProductPackage)
    {
        startPage();
        List<TbProductPackage> list = tbProductPackageService.selectTbProductPackageList(tbProductPackage);
        return getDataTable(list);
    }

    /**
     * 导出套餐管理列表
     */
    @RequiresPermissions("system:package:export")
    @Log(title = "套餐管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbProductPackage tbProductPackage)
    {
        List<TbProductPackage> list = tbProductPackageService.selectTbProductPackageList(tbProductPackage);
        ExcelUtil<TbProductPackage> util = new ExcelUtil<TbProductPackage>(TbProductPackage.class);
        util.exportExcel(response, list, "套餐管理数据");
    }

    /**
     * 获取套餐管理详细信息
     */
    @RequiresPermissions("system:package:query")
    @GetMapping(value = "/{packageId}")
    public AjaxResult getInfo(@PathVariable("packageId") Long packageId)
    {
        return success(tbProductPackageService.selectTbProductPackageByPackageId(packageId));
    }

    /**
     * 新增套餐管理
     */
    @RequiresPermissions("system:package:add")
    @Log(title = "套餐管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbProductPackage tbProductPackage)
    {
        return toAjax(tbProductPackageService.insertTbProductPackage(tbProductPackage));
    }

    /**
     * 修改套餐管理
     */
    @RequiresPermissions("system:package:edit")
    @Log(title = "套餐管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbProductPackage tbProductPackage)
    {
        return toAjax(tbProductPackageService.updateTbProductPackage(tbProductPackage));
    }

    /**
     * 删除套餐管理
     */
    @RequiresPermissions("system:package:remove")
    @Log(title = "套餐管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageIds}")
    public AjaxResult remove(@PathVariable Long[] packageIds)
    {
        return toAjax(tbProductPackageService.deleteTbProductPackageByPackageIds(packageIds));
    }
}
